# 反转Gif, PIL的版本必须升到最新
from PIL import Image, ImageSequence

src_gif = 'F:/mygif1.gif'
dst_gif = 'F:/mygif2.gif'

with Image.open(src_gif) as im:
    if im.is_animated:  # 判断是否为动态
        frames = [f.copy() for f in ImageSequence.Iterator(im)]  # 把每帧取出来
        frames.reverse()  # 反转
        frames[0].save(dst_gif, save_all=True, append_images=frames[1:])  # 形成新图

print('success!')
